using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// Represents a "drawable" geometry in GoogleEarth, like Point, LineString, LinearRing, Polygon, MultiGeometry, Model. 
    /// </summary>
    /// <remarks>This is an abstract element and cannot be used directly in a KML file. 
    /// It provides a placeholder object for all derived Geometry objects. 
    ///</remarks>
    public abstract class KmlGeometry : KmlObject, IKmlGenerator
    {

        #region Extrude
        private bool extrude;

        /// <summary>
        /// Boolean value (default=0). 
        /// Specifies whether to connect the geometric primitive (icon, line, polygon) to the ground. 
        /// Extrusion requires that the geometry's altitudeMode be either relativeToGround or 
        /// absolute and that within the coordinates element, the altitude component be greater than 0 (that is, in the air). 
        /// </summary>
        /// <value><c>true</c> if extrude; otherwise, <c>false</c>.</value>
        public bool Extrude
        {
            get { return extrude; }
            set { extrude = value; }
        } 
        #endregion

        #region Tesselate
        private bool tesselate;

        /// <summary>
        /// Boolean value (default=0). 
        /// Specifies whether to allow lines and paths to follow the terrain. 
        /// This specification applies only to LineStrings (paths) and LinearRings 
        /// (polygons) that have an altitudeMode of clampToGround. 
        /// Very long lines should enable tessellation so that they follow the curvature of the earth 
        /// (otherwise, they may go underground and be hidden). 
        /// </summary>
        /// <value><c>true</c> if tesselate; otherwise, <c>false</c>.</value>
        public bool Tesselate
        {
            get { return tesselate; }
            set { tesselate = value; }
        } 
        #endregion

        #region AltitudeMode
        KmlAltitudeModes altitudeMode = KmlAltitudeModes.clampToGround;

        /// <summary>
        /// Gets or sets the altitude mode, which specifies how altitude components in the coordinates element are interpreted.
        /// </summary>
        /// <value>The altitude mode.</value>
        public KmlAltitudeModes AltitudeMode
        {
            get { return altitudeMode; }
            set { altitudeMode = value; }
        } 
        #endregion


        #region IKmlElement Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        public virtual void GenerateKml(System.Xml.XmlTextWriter writer)
        {
            if (this.extrude)
                writer.WriteElementString("extrude", "1");
            else
                writer.WriteElementString("extrude", "0");

            if (this.tesselate)
                writer.WriteElementString("tesselate", "1");
            else
                writer.WriteElementString("tesselate", "0");

            writer.WriteElementString("altitudeMode", altitudeMode.ToString());
        }

        #endregion
    }
}
